package com.example.boot.modules.marketing.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.boot.modules.marketing.entity.CarouselItem;
import com.example.boot.modules.marketing.mapper.CarouselItemMapper;
import com.example.boot.modules.marketing.service.ICarouselItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

/**
 * <p>
 * 轮播项
 * </p>
 *
 * @author 王令
 * @since 2024-02-27
 */
@Service
public class CarouselItemServiceImpl extends ServiceImpl<CarouselItemMapper, CarouselItem> implements ICarouselItemService {

    @Transactional
    @Override
    public boolean saveBatch(Long carouselId, Collection<CarouselItem> entityList) {
        baseMapper.delete(Wrappers.<CarouselItem>lambdaQuery().eq(CarouselItem::getCarouselId, carouselId));
        int sort = 0;
        for (CarouselItem carouselItem : entityList) {
            carouselItem.setCarouselId(carouselId);
            carouselItem.setSort(sort++);
        }
        return this.saveBatch(entityList);
    }
}
